import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/', // 根路径
    redirect: '/map',
  },
  {
    path:'/home',
    name:'home',
    component:()=>import("@/views/Home/index.vue")
  },{
    path:'/map',
    name:'map',
    component:()=>import("@/views/Map/index.vue")
  },{
    path:'/log',
    name:'log',
    component:()=>import("@/views/Log/index.vue"),
    redirect: '/history',
    children:[
      {
        path:'/history',
        name:'history',
        component:()=>import("@/views/Log/TimeLine.vue"),
      },{
        path:'/upload',
        name:'upload',
        component:()=>import("@/views/Log/Upload.vue"),
      },{
        path:'/details',
        name:'details',
        component:()=>import("@/views/Log/Details.vue"),
      },
    ]
  },
  {
    path:'/user',
    name:'user',
    component:()=>import("@/views/User/index.vue"),
    redirect: '/userinfo',
    children: [
      {
        path:'/edit',
        name:'edit',
        component:()=>import("@/views/User/Edit.vue"),
      },{
        path:'/userinfo',
        name:'userinfo',
        component:()=>import("@/views/User/UserInfo.vue"),
      },{
        path:'/more',
        name:'more',
        component:()=>import("@/views/User/More.vue"),
      },
    ]
  },
  {
    path:'/setting',
    name:'setting',
    component:()=>import("@/views/User/Setting.vue"),
  },
  {
    path: '/projects',
    name:'projects',
    redirect: '/mine',
    component:()=>import("@/views/Projects/index.vue"),
    children: [
      {
        path: '/mine',
        name:'mine',
        component:()=>import("@/views/Projects/Mine.vue")
      },{
        path: '/project',
        name: 'project',
        component:()=>import("@/views/Projects/Project.vue")
      }
    ]
  },
  {
    path:'/message',
    name:'message',
    component:()=>import("@/views/Message/index.vue")
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  },
})

export default router
